/**
 * API配置文件
 * 统一管理API接口地址和配置
 */

// API基础配置
export const API_CONFIG = {
  // 基础URL
  BASE_URL: import.meta.env.VITE_API_BASE_URL || "http://localhost:8080/api",

  // WebSocket URL
  WS_URL: import.meta.env.VITE_WS_URL || "ws://localhost:8080/ws",

  // 超时配置
  TIMEOUT: 30000,

  // 重试配置
  RETRY_COUNT: 3,
  RETRY_DELAY: 1000,

  // 分页配置
  DEFAULT_PAGE_SIZE: 20,
  MAX_PAGE_SIZE: 100,
};

// API端点配置
export const API_ENDPOINTS = {
  // 认证相关
  AUTH: {
    LOGIN: "/auth/login",
    REGISTER: "/auth/register",
    REFRESH: "/auth/refresh",
    LOGOUT: "/auth/logout",
    PROFILE: "/auth/profile",
    CHANGE_PASSWORD: "/auth/change-password",
  },

  // 人格管理
  PERSONA: {
    LIST: "/persona",
    DETAIL: (id: string) => `/persona/${id}`,
    CREATE: "/persona",
    UPDATE: (id: string) => `/persona/${id}`,
    DELETE: (id: string) => `/persona/${id}`,
    SWITCH: "/persona/switch",
    CURRENT: "/persona/current",
    COOLDOWN: "/persona/cooldown",
  },

  // 聊天相关
  CHAT: {
    SEND: "/chat/send",
    HISTORY: "/chat/history",
    CONVERSATIONS: "/chat/conversations",
    CONVERSATION: (id: string) => `/chat/conversations/${id}`,
    DELETE_CONVERSATION: (id: string) => `/chat/conversations/${id}`,
    CLEAR_HISTORY: "/chat/clear",
    EXPORT: "/chat/export",
  },

  // 记忆管理
  MEMORY: {
    CREATE: "/memory/memories",
    LIST: (userId: string) => `/memory/users/${userId}/memories`,
    DETAIL: (id: string) => `/memory/memories/${id}`,
    UPDATE: (id: string) => `/memory/memories/${id}`,
    DELETE: (id: string) => `/memory/memories/${id}`,
    SEARCH: (userId: string) => `/memory/users/${userId}/memories/search`,
    STATISTICS: (userId: string) =>
      `/memory/users/${userId}/memories/statistics`,
    CLUSTERS: (userId: string) => `/memory/users/${userId}/memories/clusters`,
    BATCH_DELETE: (userId: string) => `/memory/users/${userId}/memories`,
  },

  // 用户偏好
  PREFERENCES: {
    GET: "/memory/preferences",
    UPDATE: "/memory/preferences",
    LANGUAGE: "/memory/preferences/language",
    PERSONALITY: "/memory/preferences/personality",
    NOTIFICATIONS: "/memory/preferences/notifications",
    PRIVACY: "/memory/preferences/privacy",
    RESET: "/memory/preferences/reset",
    EXPORT: "/memory/preferences/export",
    DELETE: "/memory/preferences",
  },

  // 多模态处理
  MULTIMODAL: {
    UPLOAD: "/multimodal/upload",
    PROCESS_IMAGE: "/multimodal/image/process",
    PROCESS_AUDIO: "/multimodal/audio/process",
    PROCESS_VIDEO: "/multimodal/video/process",
    GENERATE_IMAGE: "/multimodal/image/generate",
    GENERATE_AUDIO: "/multimodal/audio/generate",
    TEXT_TO_SPEECH: "/multimodal/tts",
    SPEECH_TO_TEXT: "/multimodal/stt",
  },

  // 文件管理
  FILES: {
    UPLOAD: "/files/upload",
    DOWNLOAD: (id: string) => `/files/${id}`,
    DELETE: (id: string) => `/files/${id}`,
    LIST: "/files",
    METADATA: (id: string) => `/files/${id}/metadata`,
  },

  // 伦理控制
  ETHICS: {
    FILTER_INPUT: "/ethics/filter/input",
    FILTER_OUTPUT: "/ethics/filter/output",
    BATCH_FILTER: "/ethics/filter/batch",
    CHECK_SWITCH: "/ethics/persona/check-switch",
    RECORD_SWITCH: "/ethics/persona/record-switch",
    SWITCH_STATS: "/ethics/persona/switch-stats",
    SWITCH_HISTORY: "/ethics/persona/switch-history",
    CLEAR_COOLDOWN: "/ethics/admin/clear-cooldown",
    RESET_COUNT: "/ethics/admin/reset-count",
    UPDATE_WORDS: "/ethics/admin/update-sensitive-words",
  },

  // 系统管理
  SYSTEM: {
    HEALTH: "/health",
    STATUS: "/system/status",
    METRICS: "/system/metrics",
    LOGS: "/system/logs",
  },
};

// HTTP状态码
export const HTTP_STATUS = {
  OK: 200,
  CREATED: 201,
  NO_CONTENT: 204,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  CONFLICT: 409,
  TOO_MANY_REQUESTS: 429,
  INTERNAL_SERVER_ERROR: 500,
  BAD_GATEWAY: 502,
  SERVICE_UNAVAILABLE: 503,
  GATEWAY_TIMEOUT: 504,
};

// 业务错误码
export const ERROR_CODES = {
  // 通用错误
  UNKNOWN_ERROR: "UNKNOWN_ERROR",
  NETWORK_ERROR: "NETWORK_ERROR",
  TIMEOUT_ERROR: "TIMEOUT_ERROR",

  // 认证错误
  INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
  TOKEN_EXPIRED: "TOKEN_EXPIRED",
  TOKEN_INVALID: "TOKEN_INVALID",
  UNAUTHORIZED: "UNAUTHORIZED",
  FORBIDDEN: "FORBIDDEN",

  // 业务错误
  VALIDATION_ERROR: "VALIDATION_ERROR",
  RESOURCE_NOT_FOUND: "RESOURCE_NOT_FOUND",
  RESOURCE_CONFLICT: "RESOURCE_CONFLICT",
  RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED",

  // 人格相关错误
  PERSONA_NOT_FOUND: "PERSONA_NOT_FOUND",
  PERSONA_SWITCH_COOLDOWN: "PERSONA_SWITCH_COOLDOWN",
  PERSONA_PERMISSION_DENIED: "PERSONA_PERMISSION_DENIED",

  // 内容相关错误
  CONTENT_FILTERED: "CONTENT_FILTERED",
  CONTENT_TOO_LONG: "CONTENT_TOO_LONG",
  UNSUPPORTED_FORMAT: "UNSUPPORTED_FORMAT",

  // 文件相关错误
  FILE_TOO_LARGE: "FILE_TOO_LARGE",
  FILE_TYPE_NOT_SUPPORTED: "FILE_TYPE_NOT_SUPPORTED",
  UPLOAD_FAILED: "UPLOAD_FAILED",
};

// 请求头配置
export const REQUEST_HEADERS = {
  CONTENT_TYPE: "Content-Type",
  AUTHORIZATION: "Authorization",
  X_REQUESTED_WITH: "X-Requested-With",
  X_USER_AGENT: "X-User-Agent",
  X_PERSONA_ID: "X-Persona-Id",
  X_REQUEST_ID: "X-Request-ID",
};

// 响应头配置
export const RESPONSE_HEADERS = {
  X_TOTAL_COUNT: "X-Total-Count",
  X_PAGE_NUMBER: "X-Page-Number",
  X_PAGE_SIZE: "X-Page-Size",
  X_RESPONSE_TIME: "X-Response-Time",
  X_REQUEST_ID: "X-Request-ID",
};

// WebSocket事件类型
export const WS_EVENTS = {
  // 连接事件
  CONNECT: "connect",
  DISCONNECT: "disconnect",
  ERROR: "error",
  RECONNECT: "reconnect",

  // 聊天事件
  MESSAGE: "message",
  TYPING: "typing",
  STOP_TYPING: "stop_typing",

  // 人格事件
  PERSONA_SWITCH: "persona_switch",
  PERSONA_UPDATE: "persona_update",

  // 系统事件
  SYSTEM_NOTIFICATION: "system_notification",
  MAINTENANCE: "maintenance",

  // 心跳
  PING: "ping",
  PONG: "pong",
};

// 文件类型配置
export const FILE_TYPES = {
  IMAGE: ["image/jpeg", "image/png", "image/gif", "image/webp"],
  AUDIO: ["audio/mp3", "audio/wav", "audio/ogg", "audio/m4a"],
  VIDEO: ["video/mp4", "video/webm", "video/ogg"],
  DOCUMENT: ["application/pdf", "text/plain", "application/msword"],
  ARCHIVE: ["application/zip", "application/x-rar-compressed"],
};

// 文件大小限制（字节）
export const FILE_SIZE_LIMITS = {
  IMAGE: 10 * 1024 * 1024, // 10MB
  AUDIO: 50 * 1024 * 1024, // 50MB
  VIDEO: 100 * 1024 * 1024, // 100MB
  DOCUMENT: 20 * 1024 * 1024, // 20MB
  ARCHIVE: 50 * 1024 * 1024, // 50MB
};

// 缓存配置
export const CACHE_CONFIG = {
  // 缓存键前缀
  PREFIX: "cardcaptor_sakura_",

  // 缓存时间（毫秒）
  TTL: {
    SHORT: 5 * 60 * 1000, // 5分钟
    MEDIUM: 30 * 60 * 1000, // 30分钟
    LONG: 2 * 60 * 60 * 1000, // 2小时
    VERY_LONG: 24 * 60 * 60 * 1000, // 24小时
  },
};
